<?php


DEFINE('ENTRY_PER_PAGE',10);
class PageList{
	public $start;
	public $end;
	public $kezdooldal;
	public $pagecount;
	private $route;
	
	function __construct($p){
		$this->kezdooldal=$p['offset'];
		$this->pagecount=$p['pagecount'];		
		$this->generate();
		
	}
	
	function __destruct(){
		unset($this->o);
	}
	
	function __toString(){
		return $this->o;
	}
	
	function generate(){
		if($this->pagecount>1){		
			$this->start=$this->kezdooldal-10;
			$this->end=$this->kezdooldal+10;
			
			$url=(string)new Route(Array('page'=>'{pagenum}'));
		
			$this->o='';
			if($this->start<0)$this->start=0;
			if($this->end>$this->pagecount)$this->end=$this->pagecount;
			
			if($this->kezdooldal!=0){
				//elsÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„
				$this->o.= "<a href='".str_replace('{pagenum}',0,$url)."'";
				$this->o.= " class='pagebutton".(($this->kezdooldal<2)?'_i':'');
				$this->o.="' >&laquo";
				$this->o.= "</a>";
			}
			if($this->kezdooldal>1){
				//elÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„zÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„
				$this->o.= "<a href='".str_replace('{pagenum}',($this->kezdooldal*1)-1,$url);
				$this->o.= "'  id='page_prev'  ";
				$this->o.= " class='pagebutton".(($this->kezdooldal<1	)?'_i':'');
				$this->o.="' >&lsaquo;";
				$this->o.= "</a>";
			};
			
			for($i=$this->start; $i<$this->end;$i++){
				$this->o.= "<a href='".str_replace('{pagenum}',$i,$url);
				$this->o.= "' id='page_".($i+1)."'  ";
				$this->o.= " class='pagebutton";
				if($this->kezdooldal==$i)$this->o.= "_a";
				$this->o.="' >".($i+1);
				$this->o.= "</a>";
			};
			if($this->kezdooldal<$this->pagecount-2){
				//kÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„vetkezÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„
				$this->o.= "<a href='".str_replace('{pagenum}',(($this->kezdooldal*1)+1),$url);
				$this->o.= "'  id='page_next'  ";
				$this->o.= " class='pagebutton".(($this->kezdooldal>$this->pagecount-2)?'_i':'');
				$this->o.="' >&rsaquo;";
				$this->o.= "</a>";
			};
			if($this->kezdooldal<$this->pagecount-1){
				//utolsÄ‚â€žÄąÄ…Ă„Ä…Ă„ËťÄ‚â€ąÄąÄ„
				$this->o.= "<a href='".str_replace('{pagenum}',($this->pagecount*1)-1,$url);
				$this->o.= "'  id='page_last'  ";
				$this->o.= " class='pagebutton".(($this->kezdooldal>$this->pagecount-3)?'_i':'');;
				$this->o.="' >&raquo";
				$this->o.= "</a>";
			};
		};
	}






}
